cssvalue: Add _gtk_css_value_transition()
authorBenjamin Otte <otte@redhat.com>
Fri, 30 Mar 2012 15:47:26 +0000 (17:47 +0200)
committerBenjamin Otte <otte@redhat.com>
Tue, 17 Apr 2012 06:59:15 +0000 (08:59 +0200)
Returns a value that transitions between start and end or %NULL if the
values cannot be transitioned.

So far, all implementations but numbers and rgba return NULL.

gtk/gtkcssarrayvalue.c
gtk/gtkcssenumvalue.c
gtk/gtkcssimagevalue.c
gtk/gtkcssinheritvalue.c
gtk/gtkcssinitialvalue.c
gtk/gtkcssnumbervalue.c
gtk/gtkcssrgbavalue.c
gtk/gtkcssshadowvalue.c
gtk/gtkcssstringvalue.c
gtk/gtkcssvalue.c
gtk/gtkcssvalueprivate.h

index 922fdfdeda884ae97d4cea331d8de36bfc98c85d..5260eaf653775667a211a45d024b2e0ac44a1f91 100644 (file)
@@ -59,6 +59,14 @@ gtk_css_value_array_equal (const GtkCssValue *value1,
   return TRUE;
 }
 
+static GtkCssValue *
+gtk_css_value_array_transition (GtkCssValue *start,
+                                GtkCssValue *end,
+                                double       progress)
+{
+  return NULL;
+}
+
 static void
 gtk_css_value_array_print (const GtkCssValue *value,
                            GString           *string)
@@ -82,6 +90,7 @@ gtk_css_value_array_print (const GtkCssValue *value,
 static const GtkCssValueClass GTK_CSS_VALUE_ARRAY = {
   gtk_css_value_array_free,
   gtk_css_value_array_equal,
+  gtk_css_value_array_transition,
   gtk_css_value_array_print
 };
 
index ee786b67cb1f55ce5eff88a7fef32938d47a70fc..84e986b4149adf139a7857522ffe9469f0d579d3 100644 (file)
@@ -42,6 +42,14 @@ gtk_css_value_enum_equal (const GtkCssValue *enum1,
   return enum1 == enum2;
 }
 
+static GtkCssValue *
+gtk_css_value_enum_transition (GtkCssValue *start,
+                               GtkCssValue *end,
+                               double       progress)
+{
+  return NULL;
+}
+
 static void
 gtk_css_value_enum_print (const GtkCssValue *value,
                           GString           *string)
@@ -54,6 +62,7 @@ gtk_css_value_enum_print (const GtkCssValue *value,
 static const GtkCssValueClass GTK_CSS_VALUE_BORDER_STYLE = {
   gtk_css_value_enum_free,
   gtk_css_value_enum_equal,
+  gtk_css_value_enum_transition,
   gtk_css_value_enum_print
 };
 
@@ -107,6 +116,7 @@ _gtk_css_border_style_value_get (const GtkCssValue *value)
 static const GtkCssValueClass GTK_CSS_VALUE_FONT_STYLE = {
   gtk_css_value_enum_free,
   gtk_css_value_enum_equal,
+  gtk_css_value_enum_transition,
   gtk_css_value_enum_print
 };
 
@@ -153,6 +163,7 @@ _gtk_css_font_style_value_get (const GtkCssValue *value)
 static const GtkCssValueClass GTK_CSS_VALUE_FONT_VARIANT = {
   gtk_css_value_enum_free,
   gtk_css_value_enum_equal,
+  gtk_css_value_enum_transition,
   gtk_css_value_enum_print
 };
 
@@ -198,6 +209,7 @@ _gtk_css_font_variant_value_get (const GtkCssValue *value)
 static const GtkCssValueClass GTK_CSS_VALUE_FONT_WEIGHT = {
   gtk_css_value_enum_free,
   gtk_css_value_enum_equal,
+  gtk_css_value_enum_transition,
   gtk_css_value_enum_print
 };
 
@@ -261,6 +273,7 @@ _gtk_css_font_weight_value_get (const GtkCssValue *value)
 static const GtkCssValueClass GTK_CSS_VALUE_AREA = {
   gtk_css_value_enum_free,
   gtk_css_value_enum_equal,
+  gtk_css_value_enum_transition,
   gtk_css_value_enum_print
 };
 
index f9028ae55a1a48dc137cd710637927b91c210add..0beb3fe9c7cf63b8cafd5969e01095e7a309af7b 100644 (file)
@@ -40,6 +40,14 @@ gtk_css_value_image_equal (const GtkCssValue *value1,
   return value1->image == value2->image;
 }
 
+static GtkCssValue *
+gtk_css_value_image_transition (GtkCssValue *start,
+                                GtkCssValue *end,
+                                double       progress)
+{
+  return NULL;
+}
+
 static void
 gtk_css_value_image_print (const GtkCssValue *value,
                            GString           *string)
@@ -53,6 +61,7 @@ gtk_css_value_image_print (const GtkCssValue *value,
 static const GtkCssValueClass GTK_CSS_VALUE_IMAGE = {
   gtk_css_value_image_free,
   gtk_css_value_image_equal,
+  gtk_css_value_image_transition,
   gtk_css_value_image_print
 };
 
index 427f7ec09fd4ccfddd92e11e1197383e7cb30cc9..692ec5821f1e938ac7f001fd9a5a6f73811b0566 100644 (file)
@@ -37,6 +37,14 @@ gtk_css_value_inherit_equal (const GtkCssValue *value1,
   return TRUE;
 }
 
+static GtkCssValue *
+gtk_css_value_inherit_transition (GtkCssValue *start,
+                                  GtkCssValue *end,
+                                  double       progress)
+{
+  return NULL;
+}
+
 static void
 gtk_css_value_inherit_print (const GtkCssValue *value,
                              GString           *string)
@@ -47,6 +55,7 @@ gtk_css_value_inherit_print (const GtkCssValue *value,
 static const GtkCssValueClass GTK_CSS_VALUE_INHERIT = {
   gtk_css_value_inherit_free,
   gtk_css_value_inherit_equal,
+  gtk_css_value_inherit_transition,
   gtk_css_value_inherit_print
 };
 
index 73fd38b3ae2833d9983280d28bdb62ae785c7582..640e4c5dd0aad496d6e86d2110483dc565a9954c 100644 (file)
@@ -37,6 +37,14 @@ gtk_css_value_initial_equal (const GtkCssValue *value1,
   return TRUE;
 }
 
+static GtkCssValue *
+gtk_css_value_initial_transition (GtkCssValue *start,
+                                  GtkCssValue *end,
+                                  double       progress)
+{
+  return NULL;
+}
+
 static void
 gtk_css_value_initial_print (const GtkCssValue *value,
                              GString           *string)
@@ -47,6 +55,7 @@ gtk_css_value_initial_print (const GtkCssValue *value,
 static const GtkCssValueClass GTK_CSS_VALUE_INITIAL = {
   gtk_css_value_initial_free,
   gtk_css_value_initial_equal,
+  gtk_css_value_initial_transition,
   gtk_css_value_initial_print
 };
 
index 19e4c1d198bc5019ae396dafc13f1063c0c4a960..106fd76378eebe2d4ad29b331a90542cdcd86430 100644 (file)
@@ -41,6 +41,20 @@ gtk_css_value_number_equal (const GtkCssValue *number1,
          number1->value == number2->value;
 }
 
+static GtkCssValue *
+gtk_css_value_number_transition (GtkCssValue *start,
+                                 GtkCssValue *end,
+                                 double       progress)
+{
+  /* FIXME: This needs to be supported at least for percentages,
+   * but for that we kinda need to support calc(5px + 50%) */
+  if (start->unit != end->unit)
+    return NULL;
+
+  return _gtk_css_number_value_new (start->value + (end->value - start->value) * progress,
+                                    start->unit);
+}
+
 static void
 gtk_css_value_number_print (const GtkCssValue *number,
                             GString           *string)
@@ -73,6 +87,7 @@ gtk_css_value_number_print (const GtkCssValue *number,
 static const GtkCssValueClass GTK_CSS_VALUE_NUMBER = {
   gtk_css_value_number_free,
   gtk_css_value_number_equal,
+  gtk_css_value_number_transition,
   gtk_css_value_number_print
 };
 
index f11f8b7acfd590c12d2d17eb75e0fb071c7f57af..61d8b1f8c5d0786ae442e3146760d21d3854fd05 100644 (file)
@@ -40,6 +40,22 @@ gtk_css_value_rgba_equal (const GtkCssValue *rgba1,
   return gdk_rgba_equal (&rgba1->rgba, &rgba2->rgba);
 }
 
+static GtkCssValue *
+gtk_css_value_rgba_transition (GtkCssValue *start,
+                               GtkCssValue *end,
+                               double       progress)
+{
+  GdkRGBA transition;
+
+  progress = CLAMP (progress, 0, 1);
+  transition.red = start->rgba.red + (end->rgba.red - start->rgba.red) * progress;
+  transition.green = start->rgba.green + (end->rgba.green - start->rgba.green) * progress;
+  transition.blue = start->rgba.blue + (end->rgba.blue - start->rgba.blue) * progress;
+  transition.alpha = start->rgba.alpha + (end->rgba.alpha - start->rgba.alpha) * progress;
+
+  return _gtk_css_rgba_value_new_from_rgba (&transition);
+}
+
 static void
 gtk_css_value_rgba_print (const GtkCssValue *rgba,
                           GString           *string)
@@ -52,6 +68,7 @@ gtk_css_value_rgba_print (const GtkCssValue *rgba,
 static const GtkCssValueClass GTK_CSS_VALUE_RGBA = {
   gtk_css_value_rgba_free,
   gtk_css_value_rgba_equal,
+  gtk_css_value_rgba_transition,
   gtk_css_value_rgba_print
 };
 
index 370e1dba978bf2c4ad6709e4b3701af807aa683f..2898a784771d4b69c0d6d025c6aa54e6791d9f16 100644 (file)
@@ -129,6 +129,14 @@ gtk_css_value_shadow_equal (const GtkCssValue *shadow1,
   return shadow1 == shadow2;
 }
 
+static GtkCssValue *
+gtk_css_value_shadow_transition (GtkCssValue *start,
+                                 GtkCssValue *end,
+                                 double       progress)
+{
+  return NULL;
+}
+
 static void
 gtk_css_value_shadow_print (const GtkCssValue *shadow,
                             GString           *string)
@@ -159,6 +167,7 @@ gtk_css_value_shadow_print (const GtkCssValue *shadow,
 static const GtkCssValueClass GTK_CSS_VALUE_SHADOW = {
   gtk_css_value_shadow_free,
   gtk_css_value_shadow_equal,
+  gtk_css_value_shadow_transition,
   gtk_css_value_shadow_print
 };
 
index 16debf991c4a9ecbf2154ae463e4f51113fd8cf8..aaa3ebb3d45855955c9988a6ce645092efc94ef0 100644 (file)
@@ -39,6 +39,14 @@ gtk_css_value_string_equal (const GtkCssValue *value1,
   return g_strcmp0 (value1->string, value2->string) == 0;
 }
 
+static GtkCssValue *
+gtk_css_value_string_transition (GtkCssValue *start,
+                                 GtkCssValue *end,
+                                 double       progress)
+{
+  return NULL;
+}
+
 static void
 gtk_css_value_string_print (const GtkCssValue *value,
                             GString           *str)
@@ -83,6 +91,7 @@ gtk_css_value_string_print (const GtkCssValue *value,
 static const GtkCssValueClass GTK_CSS_VALUE_STRING = {
   gtk_css_value_string_free,
   gtk_css_value_string_equal,
+  gtk_css_value_string_transition,
   gtk_css_value_string_print
 };
 
index 7dd1d7b292e4063de21ee016cc115c867db3eead..9fef5769b09673ac184f1267db93ceaa0b29545e 100644 (file)
@@ -86,6 +86,14 @@ gtk_css_value_default_equal (const GtkCssValue *value1,
   return FALSE;
 }
 
+static GtkCssValue *
+gtk_css_value_default_transition (GtkCssValue *start,
+                                  GtkCssValue *end,
+                                  double       progress)
+{
+  return NULL;
+}
+
 static void
 gtk_css_value_default_print (const GtkCssValue *value,
                              GString           *string)
@@ -100,6 +108,7 @@ gtk_css_value_default_print (const GtkCssValue *value,
 static const GtkCssValueClass GTK_CSS_VALUE_DEFAULT = {
   gtk_css_value_default_free,
   gtk_css_value_default_equal,
+  gtk_css_value_default_transition,
   gtk_css_value_default_print
 };
 
@@ -395,6 +404,20 @@ _gtk_css_value_equal (const GtkCssValue *value1,
   return value1->class->equal (value1, value2);
 }
 
+GtkCssValue *
+_gtk_css_value_transition (GtkCssValue *start,
+                           GtkCssValue *end,
+                           double       progress)
+{
+  g_return_val_if_fail (start != NULL, FALSE);
+  g_return_val_if_fail (end != NULL, FALSE);
+
+  if (start->class != end->class)
+    return NULL;
+
+  return start->class->transition (start, end, progress);
+}
+
 void
 _gtk_css_value_print (const GtkCssValue *value,
                       GString           *string)
index 7d8448c677f68dbb03f4ab5897399d06b1c277fa..6e2e89c66ff1601fe52f4072e2f154235af5764f 100644 (file)
@@ -49,6 +49,9 @@ struct _GtkCssValueClass {
 
   gboolean      (* equal)                             (const GtkCssValue          *value1,
                                                        const GtkCssValue          *value2);
+  GtkCssValue * (* transition)                        (GtkCssValue                *start,
+                                                       GtkCssValue                *end,
+                                                       double                      progress);
   void          (* print)                             (const GtkCssValue          *value,
                                                        GString                    *string);
 };
@@ -64,6 +67,9 @@ void         _gtk_css_value_unref                     (GtkCssValue
 
 gboolean     _gtk_css_value_equal                     (const GtkCssValue          *value1,
                                                        const GtkCssValue          *value2);
+GtkCssValue *_gtk_css_value_transition                (GtkCssValue                *start,
+                                                       GtkCssValue                *end,
+                                                       double                      progress);
 
 void         _gtk_css_value_print                     (const GtkCssValue          *value,
                                                        GString                    *string);